package com.gxa.controller.notice;

import com.gxa.common.R;
import com.gxa.entity.DistrictSysNotice;
import com.gxa.service.NoticeService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@Api(value = "通知公告",tags = "通知公告接口API")
@RequestMapping("/notice")
public class NoticeControlle {

    @Autowired
    private NoticeService noticeService;

    @RequestMapping(value = "/findNoticeList",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有公告信息接口",notes = "查询所有公告",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",required = true,dataType = "int",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="查找成功"),
            @ApiResponse(code=400,message="参数格式不对"),
            @ApiResponse(code=404,message="找不到此请求"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R findNoticeList(Integer currentPage,Integer pageSize){

        R r = new R();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(noticeService.findNoticeList(currentPage,pageSize));
        return r;
    }
    @RequestMapping(value = "/selectByTitle",method = RequestMethod.GET)
    @ApiOperation(value = "根据条件查询接口",notes = "条件查询",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "noticeTitle",value = "公告标题",required = false,dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "createPeople",value = "创建人",required = false,dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "createDate",value = "创建日期",required = false,dataType = "date",paramType = "query"),
            @ApiImplicitParam(name = "status",value = "状态",required = false,dataType = "int",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="查找成功"),
            @ApiResponse(code=400,message="参数格式不对"),
            @ApiResponse(code=404,message="找不到此请求"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R selectByTitle(Integer currentPage,Integer pageSize,String noticeTitle,String createPeople,Date createDate,int status){
        R r = new R();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(noticeService.selectByTitle(currentPage,pageSize,noticeTitle,createPeople,createDate,status));
        return r;
    }

    @RequestMapping(value = "/addNotice",method = RequestMethod.POST)
    @ApiOperation(value = "新增公告接口",notes = "新增公告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=400,message="参数格式不对"),
            @ApiResponse(code=404,message="找不到此请求"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R addNotice(@RequestBody@ApiParam(name = "districtSysNotice",value = "通知公告",required = true)DistrictSysNotice districtSysNotice){
        R r = new R();
        r.setCode(200);
        r.setMsg("添加成功");
        r.setData(noticeService.addNotice(districtSysNotice));
        return r;
    }

    @RequestMapping(value = "/updateNotice",method = RequestMethod.POST)
    @ApiOperation(value = "编辑公告接口",notes = "编辑公告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=400,message="参数格式不对"),
            @ApiResponse(code=404,message="找不到此请求"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R updateNotice(@RequestBody@ApiParam(name = "districtSysNotice",value = "通知公告",required = true)DistrictSysNotice districtSysNotice){
        R r = new R();
        r.setCode(200);
        r.setMsg("修改成功");
        r.setData(noticeService.updateNotice(districtSysNotice));
        return r;
    }

    @RequestMapping(value = "/delNotice",method = RequestMethod.POST)
    @ApiOperation(value = "删除公告接口",notes = "删除公告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="删除成功"),
            @ApiResponse(code=400,message="参数格式不对"),
            @ApiResponse(code=404,message="找不到此请求"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R delNotice(int noticeId){
        R r = new R();
        r.setCode(200);
        r.setMsg("删除成功");
        r.setData(noticeService.delNotice(noticeId));
        return r;
    }

    @RequestMapping(value = "/detailsNotice",method = RequestMethod.GET)
    @ApiOperation(value = "查看详情接口",notes = "查看详情",httpMethod = "GET",response = R.class)
    @ApiImplicitParam(name = "noticeId",value = "公告ID",required = true,dataType = "int",paramType = "query")
    @ApiResponses({
            @ApiResponse(code=200,message="查找成功"),
            @ApiResponse(code=400,message="参数格式不对"),
            @ApiResponse(code=404,message="找不到此请求"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R detailsNotice(int noticeId){
        R r = new R();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(noticeService.detailsNotice(noticeId));
        return r;
    }

    @RequestMapping(value = "/releaseNotice",method = RequestMethod.POST)
    @ApiOperation(value = "发布公告接口",notes = "发布公告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="发布成功"),
            @ApiResponse(code=400,message="参数格式不对"),
            @ApiResponse(code=404,message="找不到此请求"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R releaseNotice(int noticeId,Date releaseDate){
        R r = new R();
        r.setCode(200);
        r.setMsg("发布成功！");
        r.setData(noticeService.releaseNotice(noticeId,releaseDate));
        return r;
    }

    @RequestMapping(value = "/withdrawNotice",method = RequestMethod.POST)
    @ApiOperation(value = "撤回公告接口",notes = "撤回公告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="撤回成功"),
            @ApiResponse(code=400,message="参数格式不对"),
            @ApiResponse(code=404,message="找不到此请求"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R withdrawNotice(int noticeId){
        R r = new R();
        r.setCode(200);
        r.setMsg("撤回成功！");
        r.setData(noticeService.withdrawNotice(noticeId));
        return r;
    }
}
